package cn.kgc.tushu.util;

import cn.kgc.tushu.dao.EmpInt;
import cn.kgc.tushu.dao.UserInt;
import cn.kgc.tushu.dao.impl.EmpIntImpl;
import cn.kgc.tushu.dao.impl.UserInitImpl;
import cn.kgc.tushu.entity.Emp;
import cn.kgc.tushu.entity.User;

import java.util.Date;
import java.util.Scanner;

/**
 * 菜单类
 */
public class Menu {
    Scanner sc = new Scanner(System.in);
    EmpInt emps = new EmpIntImpl();
    UserInt users = new UserInitImpl();
    public void mainMenu(){
        do {
        System.out.println("1、注册");
        System.out.println("2、登陆");
        System.out.println("请选择:");
        int choice=sc.nextInt();
        switch (choice){
            case 1:
                System.out.println("请输入用户名:");
                String name = sc.next();
                System.out.println("请输入密码:");
                String pwd = sc.next();
                User user = new User(name,pwd);
                if (users.addUser(user)){
                    System.out.println("注册成功");
                }
                break;
            case 2:
                System.out.println("请输入用户名:");
                name=sc.next();
                System.out.println("请输入密码:");
                pwd=sc.next();
                if (users.checkLogin(name,pwd)) {
                    System.out.println("登陆成功!");
                    do {
                        System.out.println("1、根据图书名称查询图书信息（模糊查询）");
                        System.out.println("2、查询借书列表");
                        System.out.println("3、添加图书");
                        System.out.println("4、借书");
                        System.out.println("5、还书");
                        System.out.println("6、根据图书编号删除图书");
                        System.out.println("7、退出");
                        System.out.println("请选择:");
                        choice = sc.nextInt();
                        switch (choice) {
                            case 1:
                                System.out.println("请输入图书名称:");
                                name = sc.next();
                                emps.getByName(name);
                                break;
                            case 2:
                                emps.show();
                                break;
                            case 3:
                                System.out.println("请输入图书id");
                                int id = sc.nextInt();
                                System.out.println("请输入图书价格");
                                double price = sc.nextDouble();
                                System.out.println("请输入图书名称");
                                name = sc.next();
                                Emp emp = new Emp(id, name, price, 2, new Date());
                                emps.addBook(emp);
                                break;
                            case 4:
                                System.out.println("请输入要借的图书名称:");
                                name = sc.next();
                                emps.borroBook(name);
                                break;
                            case 5:
                                System.out.println("请输入要还的图书名称:");
                                name = sc.next();
                                emps.alsoBook(name);
                                break;
                            case 6:
                                System.out.println("请输入要删除的图书编号:");
                                id = sc.nextInt();
                                emps.deleteBooke(id);
                                break;
                            case 7:
                                System.out.println("退出程序!");
                                return;
                        }
                    }while (true);
                    }else{
                        System.out.println("用户名或密码错误,登陆失败!");
                    }
        }
        }while (true);
    }
}
